package com.geqian.file.storage;

import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;

/**
 * @author geqian
 * @date 0:47 2024/1/5
 */
public interface FileStorageTemplate {

    /**
     * 上传文件
     *
     * @param bytes
     * @param filename
     * @return
     */
    String uploadFile(byte[] bytes, String filename);

    /**
     * 上传文件
     *
     * @param is
     * @param filename
     * @return
     */
    String uploadFile(InputStream is, String filename);

    /**
     * 删除文件
     *
     * @param url
     */
    void deleteFile(String url);


    /**
     * 关闭资源
     *
     * @param closeables
     */
    default void closeResource(Closeable... closeables){
        for (Closeable closeable : closeables) {
            if (closeable != null){
                try {
                    closeable.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
